//
//  WXSDreamTalkModel.m
//  SleepBooks
//
//  Created by 王勇 on 16/9/10.
//  Copyright © 2016年 rimi. All rights reserved.
//

#import "WXSDreamTalkModel.h"

#define kRecordStartTimeKey @"recordStartTime"
#define kRecordEndTimeKey @"recordEndTime"
#define kBeginTimeKey @"beginTime"
#define kEndtimeKey @"endTime"
#define kRecordDurationKey @"recordDuration"
#define kModelFilePath @"modelFilePath"

@implementation WXSDreamTalkModel
//
//-(void)customizeMethod{
//    WXSUserModel *model = [WXSUserModel sharedModel];
//    model.username = @"ww52352";
//    model.password = @"wer";
//}



//-(NSTimeInterval)recordDuration{
//    if (self.recordStartTime && self.recordEndTime) {
//        _recordDuration =
//    }
//}


-(instancetype)init{
    self = [super init];
    if (self) {
        //当没有设定开始和结束时间的时候，beginTime，endTime为-1；这样做是为了方便“截断”在录音结束时没有说完的梦话。
        self.beginTime = -1;
        self.endTime = -1;
        self.recordStartTime = [NSDate distantPast];
        self.recordEndTime = [NSDate distantPast];
    }
    return self;
}

-(instancetype)initWithCoder:(NSCoder *)aDecode{
    self.recordStartTime = [aDecode decodeObjectForKey:kRecordStartTimeKey];
    self.recordEndTime = [aDecode decodeObjectForKey:kRecordEndTimeKey];
    self.beginTime = [aDecode decodeDoubleForKey:kBeginTimeKey];
    self.endTime = [aDecode decodeDoubleForKey:kEndtimeKey];
    self.recordDuration = [aDecode decodeDoubleForKey:kRecordDurationKey];
    self.modelFilePath = [aDecode decodeObjectForKey:kModelFilePath];
    
    return self;
}

-(void)encodeWithCoder:(NSCoder *)aCoder{
    [aCoder encodeObject:self.recordStartTime forKey:kRecordStartTimeKey];
    [aCoder encodeObject:self.recordEndTime forKey:kRecordEndTimeKey];
    [aCoder encodeDouble:self.beginTime forKey:kBeginTimeKey];
    [aCoder encodeDouble:self.endTime forKey:kEndtimeKey];
    [aCoder encodeDouble:self.recordDuration forKey:kRecordDurationKey];
    [aCoder encodeObject:self.modelFilePath forKey:kModelFilePath];
}

-(NSTimeInterval)recordDuration{
    _recordDuration = [_recordEndTime timeIntervalSinceDate:_recordStartTime];
    return _recordDuration;
}

@end
